# -*- coding: utf-8 -*-

import Image
import hashlib

from codename_bamboo.preference import IMAGE_TYPE
from codename_bamboo.preference import IMAGE_SIZE, THUMB_SIZE

def __make_uid(name, latitude, longitude):
    raw = name.encode('utf-8') + latitude.encode('utf-8') + longitude.encode('utf-8')
    message = hashlib.sha1(raw)

    return message.hexdigest()

def __make_tags_list(raw_tags):
    return raw_tags.split(',')

def __make_img_thumb(raw_file, uid):
    raw_image = Image.open(raw_file)
    raw_thumb = raw_image.copy()

    raw_image.thumbnail((IMAGE_SIZE), Image.ANTIALIAS)
    raw_thumb.thumbnail((THUMB_SIZE), Image.ANTIALIAS)

    image = '/tmp/' + uid + '.' + IMAGE_TYPE
    thumb = '/tmp/' + uid + '.thumb.' + IMAGE_TYPE

    raw_image.save(image, IMAGE_TYPE)
    raw_thumb.save(thumb, IMAGE_TYPE)

    return (open(image, 'r'), open(thumb, 'r'))
